#include <iostream>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main()
{
	int n; cin >> n;
	queue<int> stu, food;
	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;
		stu.push(tmp);
	}
	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;
		food.push(tmp);
	}

	int cur = 0;
	while (cur < food.size()) {
		if (stu.front() != food.front()) {
			stu.push(stu.front());
			stu.pop();
			cur++;
		}
		else {
			stu.pop();
			food.pop();
			cur = 0;
		}
	}
	cout << stu.size();
	return 0;
}